<?php

function showEmployeeInfo($userName, $userPassHash){
	if(isset($userName) && isset($userPassHash)){
		$tbl_name = 'employees';
		$sql="SELECT * FROM $tbl_name";

		$link = mysqli_connect("localhost", "root", "","paradigmshift_dev");

		/* check connection */
		if (mysqli_connect_errno()) {
			printf("Connect failed: %s\n", mysqli_connect_error());
			exit();
		}

		$result = $link->query($sql);
		$count = $result->num_rows;

		if($count>0){
			while($row=$result->fetch_assoc()){
       
				echo "<div class='accordion-group' ><div class='accordion-heading' >
				<div class='row-fluid btn-group'>
				<a style='text-align:left' class='accordion-toggle span8 btn btn-link' 
       data-toggle='collapse' data-parent='#accordion2' href='#collapse".$row['empID']."'"."> " . $row['empLname'] . ", ".$row['empFname']." ". $row['empID'] ." </a>
       <a class='accordion-toggle span2 btn btn-link' href='#shiftModal' role='button' data-toggle='modal' onClick='getEmpID()'>View Shift</a>

       </div></div>
       <div id='collapse".$row['empID']."' "."class='accordion-body collapse'><div class='accordion-inner'>

       <div class='container'>
       <form id='modifyEmployee".$row['empID']."' class='form-horizontal' method='post' action='modifyEmployee.php'>

       <div class='control-group'>

       <div class='controls-row'>
       <label class='control-label span2' for='fName'>First Name </label>
       <input name='fName' class='span2' value='".$row['empFname']."' type='text'>
       <label class='control-label span2' for='lName'>Last Name </label>
       <input name='lName' class='span2' value='".$row['empLname']."' type='text'>

       </div>
       </div>

       <div class='control-group'>

       <div class='controls-row'>
       <label class='control-label span2' for='sDate'>Start Date </label>
       <input name='sDate' class='span2' value='".$row['startDate']."' type='text'>
       <label class='control-label span2' for='eDate'>End Date </label>
       <input name='eDate' class='span2' value='".$row['endDate']."' type='text'>
       </div>
       </div>
       <div class='control-group'>
       <div class='controls-row'>
       <label class='control-label span2' for='status'>Status </label>
       <input name='status' class='span2' value='".$row['empStatus']."' type='text'>
       <label class='control-label span2' for='auth'>Authorized by </label>
       <input name='auth' class='span2' value='".$row['managerID']."' type='text'>
       </div>
       </div>

       <div class='control-group'>
       <div class='controls-row'>
       <label class='control-label span2' for='address'>Address </label>
       <input name='address' class='span2' value='".$row['address']."' type='text'>
       <label class='control-label span2' for='phone'>Phone </label>
       <input name='phone' class='span2' value='".$row['phoneNum']."' type='text'>
       </div>
       </div>

       <div class='control-group'>
       <div class='controls-row'>
       <label class='control-label span2' for='email'>Email </label>
       <input name='email' name='email' class='span2' value='".$row['email']."' type='text'>
       <label class='control-label span2' for='id'>EmpID</label>
       <input name='id' class='span2' value='".$row['empID']."'/>
       </div>
       </div>

       <div class='control-group'>
       <div class='controls'>
       <button name='btnSubmit' type='submit' class='btn btn-primary'>Save Changes</button>
       <button name='btnModify' type='button' class='btn btn'>Modify</button>
       </div>
       </div>

       </form>

       </div>
       </div>
       </div>
       </div>";
     }
   }
 }
}

function checkRangeSchedule($startDate,$endDate){

}

function modifyEmployee($userAuthName, $userAuthPassHash, $EmpFname, $EmpLname, $StartDate, $EndDate, $EmpStatus, $Address, $Email, $PhoneNum, $ManagerID, $EmpID){
  $link = mysqli_connect("localhost", "root", "","paradigmshift_dev");


  if(isset($userAuthName) && isset($userAuthPassHash)){
    $sql="UPDATE employees SET" . 
    " empFname='$EmpFname'," .
    " empLname='$EmpLname'," .
    " startDate='$StartDate'," .
    " endDate='$EndDate'," .
    " empStatus='$EmpStatus'," .
    " address='$Address'," .
    " email='$Email'," .
    " phoneNum='$PhoneNum'," .
    " managerID='$ManagerID'" .
    " WHERE empID='$EmpID'";

    /* check connection */
    if (mysqli_connect_errno()) {
      printf("Connect failed: %s\n", mysqli_connect_error());
      exit();
    }
    $link->query($sql);
    header("location:viewEmployee.php");
  }
}
?>